<?php
class Cms_CommentsController extends Zend_Controller_Action {

    function init(){
        CmsAuth::check();
    
    }
    
    
    public function indexAction() {
        CmsAuth::check();
//        Zend_Debug::dump($_POST);
        
        $comments = MF_Main::getInstance()->Comments;

        $all = $this->getRequest()->getParam('all');
        $checked = $this->getRequest()->getParam('checked');
        $comment_id = $this->getRequest()->getParam('comment_id');
        $this->view->comment_id = $comment_id;
        
        $commSearch = $comments->CommentSearch();
        
        //надо ли выводить проверенные
        if( $checked )
            $commSearch->checked_f = 0;
        
        $commSearch->comment_id = $comment_id;
            
        $commSearch->Make();
		
        $this->view->comments = $commSearch;
    }

    public function geticonAction(){ //загрузим данные по комменту
        CmsAuth::check();
        
        //проверяем, есть ли у комментов не проверенные
		$filter = new Zend_Filter_StripTags();
		
		$id = $filter->filter($this->getRequest()->getParam('id'));
		
		$comment = MF_Main::getInstance()->Comments->getById($id);
		echo $comment->nonCheckedCount;
        $this->_helper->layout->disableLayout();
    }
    
	public function editAction() {
		CmsAuth::check();		
		$filter = new Zend_Filter_StripTags();
		
		$id = $filter->filter($this->getRequest()->getParam('id'));
		$message = $filter->filter($this->getRequest()->getParam('message'));
		
		//ищем нужный коммент
		$comments = MF_Main::getInstance()->Comments;		
		$cs = $comments->CommentSearch();
		$cs->id = $id;
		$cs->Make();
		$comment = $cs->item(0);

		//изменяем его текст
		$comment->message = $message;

		//возвращаемся обратно
		$this->_redirect($_SERVER["HTTP_REFERER"]); 		
	}        

	public function deleteAction() {
		CmsAuth::check();		
		$filter = new Zend_Filter_StripTags();
		
		$id = $filter->filter($this->getRequest()->getParam('id'));
		$message = $filter->filter($this->getRequest()->getParam('message'));
		
		//ищем нужный коммент
		$comments = MF_Main::getInstance()->Comments;		
		$cs = $comments->CommentSearch();
		$cs->id = $id;
		$cs->Make();
		$comment = $cs->item(0);
		$comment->deleter();

		//возвращаемся обратно
		$this->_redirect($_SERVER["HTTP_REFERER"]); 		
	}   	

	public function checkAction(){
		CmsAuth::check();		
		$filter = new Zend_Filter_StripTags();
		
		$id = $filter->filter($this->getRequest()->getParam('id'));
		
		$comments = MF_Main::getInstance()->Comments;
		
		$cs = $comments->CommentSearch();
		$cs->id = $id;
		$cs->Make();
		$comment = $cs->item(0);

		$comment->checked_f = true;

		//возвращаемся обратно
		$this->_redirect($_SERVER["HTTP_REFERER"]); 	
	}
}